package com.noob.assessment.web.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 拦截器配置
 */
@Configuration
public class MVCInterceptorConfig extends WebMvcConfigurationSupport {

    /**
     * 用户拦截器 用于设置匿名用户表示
     */
    @Autowired
    private UserInterceptor userInterceptor;

    /**
     * 添加拦截器
     * 多个拦截器组成一个拦截器链
     *
     * @param registry
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则 /**表示拦截所有请求
        registry.addInterceptor(userInterceptor).addPathPatterns("/**");
        super.addInterceptors(registry);
    }

}